package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.dal.entitys.Panel;
import com.cskaoyan.shopping.dal.entitys.PanelContent;
import com.cskaoyan.shopping.dal.entitys.PanelContentItem;
import com.cskaoyan.shopping.dto.AllProductCateRequest;
import com.cskaoyan.shopping.dto.AllProductCateResponse;
import com.cskaoyan.shopping.dto.NavListResponse;
import com.cskaoyan.shopping.service.IPanelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @author why
 * @since 2022/07/29 23:01
 */
@RestController
@RequestMapping("shopping")
public class PanelController {

    @Autowired
    IPanelService IPanelService;


    // 主页显示接口
    @GetMapping("/homepage")
    public ResponseData selectHomepage(AllProductCateRequest request) {

        //ResponseData<Panel> panelResponseData = new ResponseData<>();
        List<Panel> panelList = IPanelService.selectPanel();
        //AllProductCateResponse response = IPanelService.getAllProductCate(request);
        // Panel panel1 = new Panel();

        for (Panel panel : panelList) {
                List<PanelContentItem> panelContentItemDataList =
                        IPanelService.selectPanelContentItems(panel.getId());
                panel.setPanelContentItems(panelContentItemDataList);

//            panel1.setPanelContentItems(panelContentItemDataList);
        }
        return new ResponseUtil<>().setData(panelList);

    }






    // 导航栏显示
    @GetMapping("/navigation")
    public ResponseData navigation() {
        NavListResponse response = IPanelService.selectNavigation();
        if (ShoppingRetCode.SUCCESS.getCode().equals(response.getCode())){
            return new ResponseUtil<>().setData(response.getPannelContentDtos());
        }
        return new ResponseUtil<>().setErrorMsg(response.getMsg());

    }
}
